package com.disease.chronic.Service.Impl;

import com.disease.chronic.Exception.ChronicExceptionEnum;
import com.disease.chronic.Global.Result;
import com.disease.chronic.Mappers.DailySuggestMapper;
import com.disease.chronic.Service.DailySuggestService;
import com.disease.chronic.pojo.DailySuggest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

@Service
public class DailySuggestServiceImpl implements DailySuggestService {

    @Autowired
    DailySuggestMapper dailySuggestMapper;

    @Override
    public Result insertDailySuggest(String username, String diet, String sports, String rest) {
        DailySuggest dailySuggest = new DailySuggest();
        dailySuggest.setDay(new Date(System.currentTimeMillis()));
        dailySuggest.setDiet(diet);
        dailySuggest.setUsername(username);
        dailySuggest.setRest(rest);
        dailySuggest.setSports(sports);

        dailySuggestMapper.insert(dailySuggest);

        return new Result(ChronicExceptionEnum.SUCCESS.getCode(),
                ChronicExceptionEnum.SUCCESS.getMessage());
    }

    @Override
    public Result getAllDailySuggest(String username) {
        List<DailySuggest> dailySuggests = dailySuggestMapper.selectAllDailySuggestByUsername(username);

        return new Result(ChronicExceptionEnum.SUCCESS.getCode(),
                ChronicExceptionEnum.SUCCESS.getMessage(),
                dailySuggests);
    }

    @Override
    public boolean hasSuggest(String username, Date day) {
        DailySuggest dailySuggest = dailySuggestMapper.selectByUsernameAndDay(username, day);
        return dailySuggest!=null;
    }
}

